package com.example.administrator.hqq.activity.mine;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.CompoundButton;
import android.widget.Switch;

import com.blankj.utilcode.util.SPUtils;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.base.MyActivity;
import com.example.administrator.hqq.config.LoongsConfig;
import com.zhy.autolayout.AutoLinearLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MessageAlertActivity extends MyActivity {

    @BindView(R.id.return_auto)
    AutoLinearLayout returnAuto;
    @BindView(R.id.dialogue_notification)
    Switch dialogueNotification;
    @BindView(R.id.message_notification)
    Switch messageNotification;
    @BindView(R.id.voice)
    Switch voice;
    @BindView(R.id.vibrator)
    Switch vibrator;
    private String TAG = this.getClass().getSimpleName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_alert);
        ButterKnife.bind(this);
        initview();
    }

    private void initview() {
        dialogueNotification.setChecked(SPUtils.getInstance(SPUtils.getInstance().getString(LoongsConfig.user_id))
                .getBoolean(LoongsConfig.MessageNotification.dialogueNotification, true));
        messageNotification.setChecked(SPUtils.getInstance(SPUtils.getInstance().getString(LoongsConfig.user_id))
                .getBoolean(LoongsConfig.MessageNotification.messageNotification, true));
        voice.setChecked(SPUtils.getInstance(SPUtils.getInstance().getString(LoongsConfig.user_id))
                .getBoolean(LoongsConfig.MessageNotification.voice, true));
        vibrator.setChecked(SPUtils.getInstance(SPUtils.getInstance().getString(LoongsConfig.user_id))
                .getBoolean(LoongsConfig.MessageNotification.vibrator, true));
        dialogueNotification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                SPUtils.getInstance(SPUtils.getInstance().getString(LoongsConfig.user_id)).put(LoongsConfig.MessageNotification.dialogueNotification, b);
            }
        });
        messageNotification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                SPUtils.getInstance(SPUtils.getInstance().getString(LoongsConfig.user_id)).put(LoongsConfig.MessageNotification.messageNotification, b);
            }
        });
        voice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                SPUtils.getInstance(SPUtils.getInstance().getString(LoongsConfig.user_id)).put(LoongsConfig.MessageNotification.voice, b);
            }
        });
        vibrator.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                SPUtils.getInstance(SPUtils.getInstance().getString(LoongsConfig.user_id)).put(LoongsConfig.MessageNotification.vibrator, b);
            }
        });

    }

    @OnClick(R.id.return_auto)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected String getActivityName() {
        return this.getClass().getSimpleName();
    }
}
